package com.example.fw;

import org.netbeans.jemmy.operators.*;

import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import java.util.LinkedList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: pshevchenko
 * Date: 01.04.13
 * Time: 12:16
 * To change this template use File | Settings | File Templates.
 */
public class FolderHelper extends HelperBase {

    public FolderHelper(ApplicationManager applicationManager) {
        super(applicationManager);
    }

    public FolderList getFolders() {
        List<String> folderList = new LinkedList<String>();
        JTreeOperator tree = new JTreeOperator(mainFrame);
        Object[] children = tree.getChildren(tree.getRoot());
        for (Object child : children){
            folderList.add("" + child);
        }
        return new FolderList(folderList);
    }

    public String createFolder(String folderName) {
        applicationManager.getMenuHelper().initFolderCreation();
        JDialogOperator dialogOperator = new JDialogOperator(mainFrame);
        new JTextFieldOperator(dialogOperator).setText(folderName);
        new JButtonOperator(dialogOperator, "OK").push();
        return waitMessageDialog("Warning", 3000);
    }

    public void deleteFolder(String folderName) {
        JTreeOperator tree = new JTreeOperator(mainFrame);
        //TreePath path = new TreePath(tree.getChild(tree.getRoot(), folderIndex));
        tree.selectPath(tree.findPath(folderName));
//        TreeNode[] treeNodes = tree.get()
        //tree.selectRow(folderIndex);
        //tree.clickOnPath(path);
        applicationManager.getMenuHelper().initFolderRemoval();
        JDialogOperator dialogOperator = new JDialogOperator(mainFrame);
        new JButtonOperator(dialogOperator, "OK").push();

        //Object child = tree.getChild(tree.getRoot(), folderIndex);
        //Object[] children = tree.getChildren();
//        children[folderIndex].
    }
}
